<template>
  <div class="login-wrap">
    <el-form label-position="left" :model="ruleForm"   label-width="0px" class="demo-ruleForm login-container">
      <h3 class="title">用户注册</h3>
      <el-form-item prop="userName" size="small">
        <el-input type="text" v-model="ruleForm.userName" auto-complete="off" placeholder="账号"></el-input>
      </el-form-item>

  <el-form-item prop="role" size="small">
            <el-select
              v-model="ruleForm.role"
              placeholder="请选择用户类型"
              class="usertype">
            
              <el-option label="受助者" value="受助者"></el-option>
              <el-option label="捐助者" value="捐助者"></el-option>
            </el-select>
          </el-form-item>

        <el-form-item prop="password" size="small">
        <el-input type="text" v-model="ruleForm.password" auto-complete="off" placeholder="密码"></el-input>
      </el-form-item>
        <el-form-item prop="phone" size="small">
        <el-input type="text" v-model="ruleForm.phone" auto-complete="off" placeholder="电话号码"></el-input>
      </el-form-item>
        <el-form-item prop="email" size="small">
        <el-input type="text" v-model="ruleForm.email" auto-complete="off" placeholder="邮箱地址"></el-input>
      </el-form-item>
        <el-form-item prop="realName" size="small">
        <el-input type="text" v-model="ruleForm.realName" auto-complete="off" placeholder="姓名"></el-input>
      </el-form-item>
         <el-form-item prop="sex" class="register_transp" size="small"> 
            <el-select 
              v-model="ruleForm.sex"
              placeholder="性别"
              class="usertype"
             
            >
           <el-option value="男" label="男"></el-option>
           <el-option value="女" label="女"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="idCard" size="small">
        <el-input type="text" v-model="ruleForm.idCard" auto-complete="off" placeholder="身份证号"></el-input>
      </el-form-item>
      <el-form-item prop="account" size="small">
        <el-input type="password" v-model="ruleForm.account" auto-complete="off" placeholder="账户信息"></el-input>
      </el-form-item>
      
     
      <el-form-item style="width:100%;">
        <el-button class="button1" type="primary" style="width:100%;"   @click="gohome()" >首页</el-button>
        <el-button  class="button2" type="primary" style="width:100%;" @click="resetLoginForm()" >重置</el-button>
         <el-button  class="button3" type="primary" style="width:100%;" @click="register()" >注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script type="text/ecmascript-6">
import axios from 'axios';
  
import { setCookie, getCookie, delCookie } from '../utils/util'
import md5 from 'js-md5'

export default {
  name: 'login',
  data() {
    return {
      //定义loading默认为false
      logining: false,
      // 记住密码
      rememberpwd: false,
      logining1: false,
      ruleForm: {
        role: "",
        userName: "",
        password: "",
        repassword: "",
        realName: "",
        phone: "",
        email: "",
        sex: "",
        idCard: "",
        account: "",
        address: "",
        difficultyType: ""
      },
      //rules前端验证
      rules: {
       role: [
          { required: true, message: "用户类型为必选项", trigger: "blur" }, //必填项验证
        ],
        username: [
          { required: true, message: "用户名称为必填项", trigger: "blur" }, //必填项验证
          {
            min: 1,
            max: 100,
            message: "长度在 1 到 100 个字符",
            trigger: "blur",
          }, //长度验证
        ],
        password: [
          { required: true, message: "用户密码为必填项", trigger: "blur" }, //必填项验证
          {
            min: 6,
            max: 10,
            message: "长度在 6 到 10 个字符",
            trigger: "blur",
          }, //长度验证
        ],
       
        email: [
          { required: true, message: "邮箱地址为必填项", trigger: "blur" }, //必填项验证
          { max: 30, message: "长度不能超过 30 个字符", trigger: "blur" }, //长度验证
        ],
      }
    }
  },
  // 创建完毕状态(里面是操作)
  created() {
  
 
    // 获取存在本地的用户名密码
    
    
  },
  // 里面的函数只有调用才会执行
  methods: {
   gohome(){
      this.$router.push({ path: "/" });

    },
    resetLoginForm() {
      this.ruleForm = {};
    },
    register() {
      this.$refs.registerFormRef.validate(async (valid) => {
      


        // 注册接口
      
        axios.post("http://47.106.193.50:8080/userRegister",this.registerForm).then(res=>{
        
            if (res.data.code == "200") {
          this.$message.success(res.data.msg);
          this.$router.push({ path: "/login" });
        } else {
          this.$message.error(res.data.msg);
        }
        })

      
      });
    },
   
  }
}
</script>

<style scoped>
.button1{
 
}
.el-button+.el-button {
     margin-left: 0px; 
}
.button2{
  margin-top:10px;
 
}
.button3{
  margin-top:10px;
 
}
.login-wrap {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding-top: 10%;
  background-image: url();

  /* background-color: #112346; */
  background-repeat: no-repeat;
  background-position: center right;
  background-size: 100%;
}
.login-container {
  border-radius: 10px;
  margin: 0px auto;
  width: 400px;
  padding: 10px 35px 5px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  text-align: left;
  box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);
  margin-top:-30px

}
.title {
  margin: 0px auto 40px auto;
  text-align: center;
  color: #505458;
}
.remember {
  margin: 0px 0px 35px 0px;
}
.code-box {
  text-align: right;
}
.codeimg {
  height: 40px;
}
</style>